﻿(function() {
  var __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  this.CustomModel = (function(_super) {
    var _fillObjectFromUrl;

    __extends(CustomModel, _super);

    function CustomModel() {
      return CustomModel.__super__.constructor.apply(this, arguments);
    }

    CustomModel.prototype.fetch = function() {
      Loading.Start();
      return CustomModel.__super__.fetch.apply(this, arguments);
    };

    CustomModel.prototype.FillModelFromUrl = function() {
      return this.attributes = _fillObjectFromUrl(this.attributes);
    };

    _fillObjectFromUrl = function(object, prefix) {
      var key, val, value;
      if (prefix == null) {
        prefix = '';
      }
      for (key in object) {
        value = object[key];
        if (typeof value === 'object') {
          object[key] = _fillObjectFromUrl(object[key], key + ".");
        } else {
          val = Url.GetParameterByName(prefix + key);
          if (val.length) {
            object[key] = val;
          }
        }
      }
      return object;
    };

    return CustomModel;

  })(Backbone.Model);

}).call(this);
